package com.vspush.manage;

import java.net.InetSocketAddress;

import com.alibaba.fastjson.JSON;
import com.vspush.manage.type.MessageHeader;
import com.vspush.manage.type.MesssageType;
import com.vspush.udp.model.LinkUser;
import com.vspush.util.Base164;

public class StartMessge extends MessageAbstract {

	@Override
	public void sendMessage(String userName, String msg) {
		this.sendMessage(userName, msg, MesssageType.start);
	}
	
	public void startError(InetSocketAddress  isa){
		this.sendMessage(isa, "",MesssageType.error);
	}
	public void startOk(InetSocketAddress  isa){
		this.sendMessage(isa, "",MesssageType.ok);
	}

	public LinkUser getUserbyMsg(String msg) {
		String name = MessageHeader.u.getName();
		int start = msg.indexOf(name) + name.length();
		if (start != -1) {
			int end = msg.indexOf(name.substring(0, 1), start);
			String u = null;
			if (end != -1) {
				u = msg.substring(start, end);
			}else{
				u = msg.substring(start);
			}
			u = Base164.decodeToString(u);
			LinkUser user = JSON.parseObject(u, LinkUser.class);
			return user;
		}
		return null;
	}

}
